package com.example.win.android_banduyujia.peopleactivity.fragment.doorfragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.activity.activity.dooractivity.cancelActivity;
import com.example.win.android_banduyujia.peopleactivity.activity.activity.dooractivity.classesActivity;
import com.example.win.android_banduyujia.peopleactivity.activity.activity.dooractivity.pckageActivity;
import com.example.win.android_banduyujia.peopleactivity.activity.activity.dooractivity.priceActivity;
import com.example.win.android_banduyujia.peopleactivity.adapter.ExpandAdapter;
import com.example.win.android_banduyujia.entity.DoorEntity;

import java.util.HashMap;
import java.util.List;

/**
 * Created by huchun on 2015/8/22.
 */
public class NodoorFragment extends Fragment implements View.OnClickListener, ExpandableListView.OnGroupClickListener, ExpandableListView.OnChildClickListener {
    public static final String  TAG = NodoorFragment.class.getSimpleName();

    private LinearLayout mLayoutNumber, mLayoutPrice, mLayoutPackage, mLayoutCancel;
    private Fragment      fragment;
    private ExpandableListView mExpandableListView;
    private Button mBtnSubmit;

    private ExpandAdapter mExpandAdapter;
    private DoorEntity mdoorentity;
    private boolean  isFirst = true;

    private List<String> listDataHeader;
    private HashMap<String, List<String>> listDataChild;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View  view = inflater.inflate(R.layout.fragment_no_door_page, null);

        InitViews(view);

        return view;
    }

    private void InitViews(View view) {
        mLayoutNumber = (LinearLayout)view.findViewById(R.id.layout_linear_item_number);
        mLayoutPrice = (LinearLayout)view.findViewById(R.id.layout_linear_item_price);
        mLayoutPackage = (LinearLayout)view.findViewById(R.id.layout_linear_item_package_price);
        mLayoutCancel = (LinearLayout)view.findViewById(R.id.layout_linear_item_cancel);
        mBtnSubmit = (Button)view.findViewById(R.id.layout_button_data_ok);

        mExpandableListView= (ExpandableListView) view.findViewById(R.id.door_expandableListView);
        mExpandAdapter = new ExpandAdapter(getActivity());
        mExpandableListView.setAdapter(mExpandAdapter);
        mExpandableListView.expandGroup(0);
        mExpandableListView.setOnGroupClickListener(this);
        mExpandableListView.setOnChildClickListener(this);

        mLayoutNumber.setOnClickListener(this);
        mLayoutPrice.setOnClickListener(this);
        mLayoutPackage.setOnClickListener(this);
        mLayoutCancel.setOnClickListener(this);
        mBtnSubmit.setOnClickListener(this);
    }


    public void onClick(View v) {
        switch (v.getId()){
            case R.id.layout_linear_item_number: // 上课人数
                numberActivity();
                break;
            case R.id.layout_linear_item_price: // 单课时价格
                priceActivity();
                break;
            case R.id.layout_linear_item_package_price: // 套餐价格
                packageActivity();
                break;
            case R.id.layout_linear_item_cancel:  // 取消政策
                cancelActivity();
                break;
            case R.id.layout_button_data_ok: // 确认发布
                okActivity();
                break;
        }
    }

    private void numberActivity() {
        startActivity(new Intent(getActivity(), classesActivity.class));
    }

    private void priceActivity() {
        startActivity(new Intent(getActivity(), priceActivity.class));
    }

    private void packageActivity() {
        startActivity(new Intent(getActivity(),pckageActivity.class));
    }

    private void cancelActivity() {
        startActivity(new Intent(getActivity(), cancelActivity.class));
    }

    private void okActivity() {

    }


    @Override
    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
        return false;
    }

    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
        Log.e(TAG, "groupPosition=" + groupPosition + ",childPosition=" + childPosition);


        return false;
    }
}

